﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using EPiMVC.Routing;
using EPiServer.Core;

namespace EPiMVC.Html
{
    public static class LinkExtensions
    {
        public static string PageLink(this HtmlHelper helper, string linkText, PageReference pageReference)
        {
            RouteValueDictionary values = new RouteValueDictionary();
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return HtmlHelper.GenerateRouteLink(helper.ViewContext.RequestContext, helper.RouteCollection, linkText, null, values,
                                     new Dictionary<string, object>());
        }

        public static string PageLink(this HtmlHelper helper, string linkText, PageReference pageReference, object routeValues)
        {
            RouteValueDictionary values = new RouteValueDictionary(routeValues);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return HtmlHelper.GenerateRouteLink(helper.ViewContext.RequestContext, helper.RouteCollection, linkText, null, values,
                                     new Dictionary<string, object>());
        }

        public static string PageLink(this HtmlHelper helper, string linkText, string action, PageReference pageReference)
        {
            RouteValueDictionary values = new RouteValueDictionary();
            values.Add("action", action);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return HtmlHelper.GenerateRouteLink(helper.ViewContext.RequestContext, helper.RouteCollection, linkText, null, values,
                                     new Dictionary<string, object>());
        }

        public static string PageLink(this HtmlHelper helper, string linkText, string action, PageReference pageReference, object routeValues)
        {
            RouteValueDictionary values = new RouteValueDictionary(routeValues);
            values.Add("action", action);
            values.Add(EPiServerRoute.PageReferenceKey, pageReference);
            return HtmlHelper.GenerateRouteLink(helper.ViewContext.RequestContext, helper.RouteCollection, linkText, null, values,
                                     new Dictionary<string, object>());
        }
    }
}
